<?php
// +----------------------------------------------------------------------
// | 中联致远服务端框架
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://www.zhongliansoft.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: tony <tanyu@zhongliansoft.com>
// +----------------------------------------------------------------------

namespace app\common\model;
use think\Validate;
use think\model\concern\SoftDelete;
use think\facade\Log;

class CwStructCache extends Common
{ 
    /**
     * @param $post
     *
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function tableData($post)
    {
        if(isset($post['limit'])){
            $limit = $post['limit'];
        }else{
            $limit = config('paginate.list_rows');
        }

        $tableWhere = $this->tableWhere($post);
        $list = $this->field($tableWhere['field'])->where($tableWhere['where'])->paginate($limit);
        $data = $this->tableFormat($list->getCollection());         //返回的数据格式化，并渲染成table所需要的最终的显示数据类型

        $re['code'] = 0;
        $re['msg'] = '';
        $re['count'] = $list->total();
        $re['data'] = $data;

        return $re;
    }
 
    //where搜索条件
    protected function tableWhere($post)
    {
        $where = [];
        $result['where'] = $where;
        $result['field'] = "*";
        return $result;
    }

    /**
     * @param $list
     *
     * @return mixed
     */
    protected function tableFormat($list)
    {
        return $list;
    }

    /**
     * @param $list
     *
     * @return mixed
     */
    public function getSpecicaltiesList()
    {
        // 这里要获取部门+专业+年级的组合
        $list = $this->field(["bmmc, zymc, rxnd, case when xsxzdm = '01' then '普招本科' when xsxzdm = '03' then '普招专升本' when xsxzdm = '06' then '普招专科' when xsxzdm = '21' then '中专' when xsxzdm = '23' then '五年制（中专）' when xsxzdm = '24' then '五年制（大专）' end xsxz"])->select()->toArray();

        $nameList = [];
        foreach ($list as $key => $val) {
            $nameList[] = $val['bmmc'].'-'.$val['zymc'].'-'.$val['rxnd'].'-'.$val['xsxz'];
        }
        
        return $nameList;
    }

    /**
     * @param $list
     *
     * @return mixed
     */
    public function getClassesList()
    {
        $list = $this->field(["bjmc"])->select()->toArray();

        $nameList = [];
        foreach ($list as $key => $val) {
            $nameList[] = $val['bjmc'];
        }
        
        return $nameList;
    }

    // bjmc => bmmc
    public function getClassDeptList()
    {
        $list       = [];
        $list = $this->field('bmmc, bjmc')->select();

        $classDeptArray = $list->toArray();
        return $classDeptArray;
    }

    // bjmc => zymc
    public function getClassSpecList()
    {
        $list       = [];
        $list = $this->field('zymc, bjmc')->select();

        $classSpecArray = $list->toArray();
        return $classSpecArray;
    }
}